﻿using System;

namespace Sencha.Serialization.Bson.Utils
{
	public static class BsonWriterExtentions
	{
		public static void WriteObjectId(this IBsonWriter writer, BsonObjectId value)
		{
			writer.Write(BsonToken.ObjectId, value);
		}
		public static void WriteTimestamp(this IBsonWriter writer, BsonTimestamp value)
		{
			writer.Write(BsonToken.Timestamp, value);
		}
		public static void WriteDateTime(this IBsonWriter writer, BsonDateTime value)
		{
			writer.Write(BsonToken.DateTime, value);
		}

		public static void WriteBinary(this IBsonWriter writer, BsonBinary value)
		{
			if (value == null)
				writer.WriteNull();
			else
				writer.Write(BsonToken.Binary, value);
		}
		public static void WriteBinary(this IBsonWriter writer, byte[] value)
		{
			if (value == null)
				writer.WriteNull();
			else
				writer.Write(BsonToken.Binary, value);
		}
		public static void WriteBinary(this IBsonWriter writer, byte[] value, int startIndex, int count)
		{
			if (value == null)
				writer.WriteNull();
			else
				writer.Write(BsonToken.Binary, new BsonBinary(0, value, startIndex, count));
		}
		public static void WriteJavaScript(this IBsonWriter writer, BsonJavaScript value)
		{
			if (value == null)
				writer.WriteNull();
			else
				writer.Write(BsonToken.JavaScript, value);
		}
		public static void WriteJavaScript(this IBsonWriter writer, string value)
		{
			if (value == null)
				writer.WriteNull();
			else
				writer.Write(BsonToken.JavaScript, value);
		}
		public static void WriteJavaScriptWithScope(this IBsonWriter writer, BsonJavaScriptWithScope value)
		{
			if (value == null)
				writer.WriteNull();
			else
				writer.Write(BsonToken.JavaScriptWithScope, value);
		}
		public static void WriteSymbol(this IBsonWriter writer, BsonSymbol value)
		{
			if (value == null)
				writer.WriteNull();
			else
				writer.Write(BsonToken.Symbol, value);
		}
		public static void WriteSymbol(this IBsonWriter writer, string value)
		{
			if (value == null)
				writer.WriteNull();
			else
				writer.Write(BsonToken.Symbol, value);
		}
		public static void WriteRegex(this IBsonWriter writer, BsonRegex value)
		{
			if (value == null)
				writer.WriteNull();
			else
				writer.Write(BsonToken.Regex, value);
		}
		public static void WriteRegex(this IBsonWriter writer, System.Text.RegularExpressions.Regex value)
		{
			if (value == null)
				writer.WriteNull();
			else
				writer.Write(BsonToken.Regex, value);
		}
	}
}
